package com.test.card.handler;

import com.test.card.domain.ApiReponse;
import com.test.card.enums.ApiResponseEnum;
import com.test.card.exception.CardException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class ExceptionHandle {
    private Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = {CardException.class})
    @ResponseBody
    public ApiReponse<Object> handle(CardException e, HttpServletRequest request, HttpServletResponse response){
        logger.error("系统异常，{}",e);
        return new ApiReponse<>(e.getCode(),e.getMsg(),null);
    }

    @ExceptionHandler(value = {Exception.class})
    @ResponseBody
    public ApiReponse<Object> handle(Exception e, HttpServletRequest request, HttpServletResponse response){
        logger.error("系统异常，{}",e);
        return new ApiReponse<>(ApiResponseEnum.SYSTEM_ERROR,null);
    }

}
